<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
    <!-- 引入样式 -->
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <!-- 引入组件库 -->
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>

</head>
<body>
    <div id="app">
        <el-form :inline="true" class="demo-form-inline">
            <el-form-item label="请输入您的账号：">
                <el-input type="text" v-model="yinput.account" placeholder="请输入您的帐号..."></el-input>
            </el-form-item>
            <el-form-item label="请输入您的密码：">
                <el-input type="password" v-model="yinput.password" placeholder="请输入您的密码..."></el-input>
            </el-form-item>

            <el-form-item>
                <el-button type="primary" @click="onSubmitUser">用户登录</el-button>
                <el-button type="primary" @click="onSubmitAdmin">管理员登录</el-button>
            </el-form-item>
        </el-form>

    </div>

    <script>
        axios.defaults.withCredentials=true;
        new Vue({
            el:'#app',
            data(){
                return {
                    yinput:{
                        account:'',
                        password:''
                    }
                }
            },
            methods:{
                onSubmitUser:function (){
                    let _this=this;
                    axios.get('http://localhost:8090/api/user/login?account='
                        +this.yinput.account+"&password="+this.yinput.password)
                        .then(function (response) {
                            console.log(response.data.results);
                            localStorage.setItem("currentuserper",response.data.results.per);
                            localStorage.setItem("currentuserid",response.data.results.id);
                        })
                        .catch(function (error) {
                            console.log(error);
                        });
                },
                onSubmitAdmin:function (){
                    let _this=this;
                    axios.get('http://localhost:8090/api/admin/login?account='
                        +this.yinput.account+"&password="+this.yinput.password)
                        .then(function (response) {
                            console.log(response.data.results);
                            localStorage.setItem("currentuserper",response.data.results.per);//把当前用户的权限和id都存到浏览器里
                            localStorage.setItem("currentuserid",response.data.results.id);

                        })
                        .catch(function (error) {
                            console.log(error);
                        });
                }
            }
        });
    </script>
</body>
</html>